package logic

import (
	"context"
	"ykone/ykonerpc/ykonerpc"

	"ykone/api/internal/svc"
	"ykone/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProduceaddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProduceaddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProduceaddLogic {
	return &ProduceaddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProduceaddLogic) Produceadd(req *types.ProduceaddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	add, err := l.svcCtx.YkOneRpc.ProduceAdd(l.ctx, &ykonerpc.ProduceAddRequest{
		ProductName:  req.ProductName,
		ProductStore: req.ProductStore,
		Price:        req.Price,
		Img:          req.Img,
		UserID:       req.UserId,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    "500",
			Data:    "",
		}, nil
	}
	return &types.Response{
		Message: "添加成功",
		Code:    "200",
		Data:    add,
	}, nil
}
